package org.lingshi.shopping_search_customer_api.controller;

import net.bytebuddy.agent.builder.AgentBuilder;
import org.apache.dubbo.config.annotation.DubboReference;
import org.lingshi.common.entity.GoodsSearchParam;
import org.lingshi.common.entity.GoodsSearchResult;
import org.lingshi.common.result.BaseResult;
import org.lingshi.common.service.IGoodsSearchService;
import org.lingshi.common.service.IGoodsService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/goodsSearch")
public class GoodsSearchController {
    @DubboReference
    private IGoodsSearchService goodsSearchService;

    @DubboReference
    private IGoodsService goodsService;

    /**
     * 商品搜索
     * @param goodsSearchParam 搜索参数
     * @return 搜索结果
     */
    @PostMapping("/search")
    public BaseResult search(@RequestBody GoodsSearchParam goodsSearchParam){
        GoodsSearchResult goodsSearchResult = goodsSearchService.search(goodsSearchParam);
        return BaseResult.success(goodsSearchResult);
    }

    @GetMapping("/autoSuggest")
    public BaseResult autoSuggest(String keyword){
        List<String> suggest = goodsSearchService.autoSuggest(keyword);
        return BaseResult.success(suggest);
    }

    @GetMapping("/findDesc")
    public BaseResult findDesc(Long id){
        return BaseResult.success(goodsService.findDescById(id));
    }
}
